Skip to content

Conversation

dnickless
Copy link
Contributor

@dnickless dnickless commented Jan 6, 2021

Fixes https://jira.mongodb.org/browse/CSHARP-2450.

Kindly review my individual check-ins as all 3 check-ins affect the same file and will be confusing in a single comparison.

The most recent check-in contains the most important change: This is where I trade a tiny little bit of increasing complexity (cloning a small HashSet) on the way less likely write-scenario for a substantially better performing read-scenario.

Daniel Hegener added 3 commits February 1, 2021 21:05
…KnownTypesAreRegistered (called by BsonSerializer.LookupActualType which is on the hot path during deserialization) by switching to the (unfortunately not generic) Hashtable type instead of a HashSet<T>. Hashtable is safe for concurrent reads (as per https://docs.microsoft.com/en-us/dotnet/api/system.collections.hashtable?redirectedfrom=MSDN&view=netframework-4.7.2#thread-safety). This is a safe change since the "__typesWithRegisteredKnownTypes" variable is really just a local cache to avoid registering already registered types. It has no effect anywhere else.
…pe which is on the hot path during deserialization by locking a single dictionary lookup only. The HashSet<T> instances that are tracked inside the Hashtable are kind of immutable now as they get wholly replaced inside the dictionary instead of updated which allows consumers to safely iterate over the old instances, thus allowing the read-locked section to be shortened.
@dnickless
Copy link
Contributor Author

Any chance someone could look at this? We're eagerly waiting to see this or the other other PR #347 in a next version of the driver. Thanks!

@JamesKovacs
Copy link
Contributor

Hi, @dnickless,

We have investigated the performance improvements observed in this PR. Specifically we examined each individual code change to understand why it improved performance with the intention of applying the smallest possible change with the biggest net impact. We are proposing more minimal change that actually has a greater performance impact in #482. We appreciate you drawing our attention to this potential improvement. Thank you for the continued collaboration!

Sincerely,
James

@JamesKovacs
Copy link
Contributor

This PR has been superseded by PR #482.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants